# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=upterm
pkgver=0.13.5
pkgrel=0
pkgdesc="Secure terminal sharing"
url="https://upterm.dev/"
arch="all"
license="Apache-2.0"
makedepends="go"
checkdepends="bash"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-server
	$pkgname-server-openrc
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/owenthereal/upterm/archive/refs/tags/v$pkgver.tar.gz
	uptermd.initd
	uptermd.confd
	"
options="net !check" # fail on network flakiness

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	for cli in upterm uptermd; do
		go build -v -o out/$cli ./cmd/$cli
	done

	# Re-generate completion files and man pages
	go run cmd/gendoc/main.go
}

check() {
	go test ./...
}

package() {
	install -Dm755 out/upterm out/uptermd \
		-t "$pkgdir"/usr/bin/

	install -Dm644 etc/man/man1/*.1 -t "$pkgdir"/usr/share/man/man1/
	install -Dm644 etc/completion/upterm.bash_completion.sh \
		"$pkgdir"/usr/share/bash-completion/completions/upterm
	install -Dm644 etc/completion/upterm.zsh_completion \
		"$pkgdir"/usr/share/zsh/site-functions/_upterm
	install -Dm755 "$srcdir"/uptermd.initd "$pkgdir"/etc/init.d/uptermd
	install -Dm644 "$srcdir"/uptermd.confd "$pkgdir"/etc/conf.d/uptermd
}

server() {
	pkgdesc="$pkgdesc (server)"
	amove usr/bin/uptermd
}

sha512sums="
c3317b56e7912e74fd98f83dcfc92ddd322afd659d49c4d84555de10d90f7b4de54b09d69ec224087390712d99269096470edfd2df6d8eb61134d0cb6bb869a5  upterm-0.13.5.tar.gz
45165ca78a4f399583baaf151588d046b075c9632574720ec49887e542f8874fb63907ce390f40505d13499f2f35caa4b9aca5a10163c12c838fc9621ec897bd  uptermd.initd
8ffec044a02b1a0cd5ca7b5e31fdb6f1ee958b16e346c913b9387d6a5ef4fb8b9e7ac881d0b449eeb1e0fca945f401a5db0572cfcc5684028d1709588ff8e61b  uptermd.confd
"
